function GuiParcelUtils() {
};

GuiParcelUtils.tasks = function(gui, user, date, data, callbackFunc, callbackFunc1, callbackFunc2) {
  var tr, td, popupBox = new ModulePopupBox(), _self = this;

  var tasks = data[0].data;
  var notes = data['note'];
  var models = data['pz_model'];
  var states = data['pz_model_state'];
  var transitions = data['pz_model_transition'];
  this._queue = data[0].queue;
  this._cond = data[0].condition;
  this._select = data['table_select'];
  this._join = data['table_join'];
  DOMUtils.removeTableRows(gui.tasks, 1);

  if (tasks.length == 0) {
    tr = gui.tasks.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 10;
    td.style.height = '23px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode('n/a'));
  }
  
  for (var i = 0, il = tasks.length; i < il; i++) {
    var task = tasks[i];
    tr = gui.tasks.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#ececec' : '#fff';
    tr.style.color = (task.deadline && parseInt((task.deadline - date) / 86400, 10) <= 0) ? '#ff0000' : '#000000';

    td = tr.insertCell(-1);
    td.style.height = '23px';
    td.style.borderRight = 'solid 1px #bbb';
    td.style.padding = '0 5px';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.branch) ? task.branch : '-'));
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('Parcel ' + task.code));
    var note = document.createElement('button');
    var count = 0;
    for (var j = 0, jl = notes.length; j < jl; j++) {
      var n = notes[j];
      if (n.id == task.id) {
        count = n.value;
      }
    }
    note.className = (count == 0) ? "notebtn" : "notebtn1";
    note.style.cursor = 'pointer';
    note.style.margin = '0 0 0 5px';
    note._task = task;
    note.onclick = function() { div = document.createElement('div');
                                pos = DOMUtils.findPos(this);
                                MiscUtils.dialog(popupBox, pos, div, null, null, { t: 'Details', width: 760, height: 50 });
                                new ModuleDialogNote(document, div, 740, 30, user, date, { task: this._task, popupBox: popupBox, callback: callbackFunc1, pos: pos });
                                return false;
                              };
                              
    td.appendChild(note);
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(SimpleDate.format(SimpleDate.fromStamp(task.created_date))));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.received_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.received_date)) : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.photographer) ? task.photographer : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.photographer2) ? task.photographer2 : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }

    td.appendChild(document.createTextNode((task.designer) ? task.designer : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((PPublishUtils.object(task.state_id, states)) ? PPublishUtils.object(task.state_id, states).name : ''));

    var a1 = document.createElement('a');
    a1.href = '#';
    a1._task = task;
    a1.style.fontSize = '11px';
    a1.style.paddingLeft = '3px';
    a1.appendChild(document.createTextNode('Log'))
    a1.onclick = function() { var pos = DOMUtils.findPos(this);
                              var div = document.createElement('div');
                              var func1 = function() { popupBox._close();
                                                       callbackFunc();
                                                       if (callbackFunc2) {
                                                         callbackFunc2();
                                                       }
                                                     }
                              MiscUtils.dialog(popupBox, pos, div, func1, null, {t: 'History', width: 780, height: 50});
                              new ModuleDialogHistory(document, div, 500, 30, user, date, { object: this._task, models: models, states: states, transitions: transitions });
                              return false;
                            };
    td.appendChild(a1);
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.deadline) ? parseInt((task.deadline - date) / 86400, 10) : '-'));
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    if (task.model_id != 2) {
      ModelUtils.btns(task, models, states, transitions, td, user, date, callbackFunc, callbackFunc2);
    } else {
      var a = document.createElement('a');
      a.href = '?t=reviewmail&i=' + task.id;
      a.appendChild(document.createTextNode('Review'));
      td.appendChild(a);
    }
  }
};
